<!DOCTYPE html>
<html>

<head>
    <title>编辑校友名片</title>
    <meta name="keywords" content="{$site_info.site_seo_keywords|default=''}" />
    <meta name="description" content="{$site_info.site_seo_description|default=''}">
    <include file="public@head" />
    <style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
    #address-selector select{
        width: 33.3%;
        float: left;
    }
    </style>
    <script type="text/html" id="photos-item-tpl">
        <li id="saved-image{id}">
            <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
            <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}" style="width: 200px;" title="图片名称">
            <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;" onclick="imagePreviewDialog(this.src);">
            <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
            <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
        </li>
    </script>
    <script type="text/html" id="files-item-tpl">
        <li id="saved-file{id}">
            <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
            <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}" style="width: 200px;" title="文件名称">
            <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
            <a href="javascript:uploadOne('图片上传','#file-{id}','file');">替换</a>
            <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
        </li>
    </script>
</head>

<body class="body-white">
    <div class="container tc-main">
        <div class="row">
            <div class="wrap js-check-wrap col-md-12">
                <h3 class="text-center">梅陇客栈 · 编辑校友名片</h3>
                <br>
                <form action="{:url('businesscard/Card/editCard')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
                    <div class="row">
                        <div class="col-md-6">
                            <table class="table table-bordered">
                                <tr>
                                    <th width="85">所属行业<span class="form-required">*</span></th>
                                    <td>
                                        <input class="form-control" type="text" required value="{:implode(' ',$post_categories)}" placeholder="请选择分类" onclick="doSelectCategory();" id="js-categories-name-input" readonly/>
                                        <input class="form-control" type="hidden" value="{$post_category_ids}" name="post[categories]" id="js-categories-id-input" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>姓名<span class="form-required">*</span></th>
                                    <td>
                                        <input type="hidden" name="post[id]" value="{$post.id}">
                                        <input class="form-control" type="text" name="post[name]" id="name" required value="{$post.name}" placeholder="请输入姓名" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>班级<span class="form-required">*</span></th>
                                    <td>
                                        <input class="form-control" type="text" name="post[class]" id="class" required value="{$post.class}" placeholder="请输入班级，如2005级化工3班" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>学号</th>
                                    <td>
                                        <input class="form-control" type="text" name="post[stu_no]" id="class" value="{$post.stu_no}" placeholder="请输入学号" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>手机<span class="form-required">*</span></th>
                                    <td>
                                        <input class="form-control" type="text" name="post[mobile_phone]" id="mobile_phone" value="{$post.mobile_phone}" placeholder="请输入手机号" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>邮箱</th>
                                    <td>
                                        <input class="form-control" type="text" name="post[email]" id="email" value="{$post.email}" placeholder="请输入邮箱" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>微信号</th>
                                    <td>
                                        <input class="form-control" type="text" name="post[wechat]" id="wechat" value="{$post.wechat}" placeholder="请输入微信号" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>个人简介</th>
                                    <td>
                                        <textarea class="form-control" name="post[summary]" style="height: 50px;" placeholder="请填一句话简介">{$post.summary}</textarea>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-6">
                            <table class="table table-bordered">
                                <tr>
                                    <th width="85">所在区域</th>
                                    <td>
                                        <input class="form-control" type="hidden" name="post[address]" id="address" value="{$post.address}" />
                                        <div id="address-selector" data-autoselect="3">
                                            <select class="form-control col-md-4"></select>
                                            <select class="form-control col-md-4"></select>
                                            <select class="form-control col-md-4"></select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th>工作单位<span class="form-required">*</span></th>
                                    <td>
                                        <input class="form-control" type="text" name="post[employer]" id="employer" required value="{$post.employer}" placeholder="请输入工作单位" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>职位名称</th>
                                    <td>
                                        <input class="form-control" type="text" name="post[position]" id="position" value="{$post.position}" placeholder="请输入职位名称" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>工作电话</th>
                                    <td>
                                        <input class="form-control" type="text" name="post[work_tel]" id="work_tel" value="{$post.work_tel}" placeholder="请输入工作电话" />
                                    </td>
                                </tr>
                                <tr>
                                    <th>标签</th>
                                    <td>
                                        <input class="form-control" type="text" name="post[card_tags]" id="keywords" value="{$post.card_tags}" placeholder="请输入标签">
                                        <p class="help-block" style="margin: 0">多个标签之间用英文逗号隔开</p>
                                    </td>
                                </tr>
                                <tr>
                                    <th>发布时间</th>
                                    <td>
                                        <input class="form-control js-bootstrap-datetime" type="text" name="post[published_time]" value="{:date('Y-m-d H:i',$post['published_time'])}">
                                    </td>
                                </tr>
                                <tr>
                                    <th>状态</th>
                                    <php>
                                        $status_yes=$post['card_status']==1?"checked":"";
                                    </php>
                                    <td>
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" name="post[card_status]" value="1" {$status_yes}>发布
                                            </label>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-12">
                            <table class="table table-bordered">
                                <tr>
                                    <th width="85">详细介绍</th>
                                    <td>
                                        <script type="text/plain" id="content" name="post[card_content]">{$post.card_content}</script>
                                    </td>
                                </tr>
                                <tr>
                                    <th>相册</th>
                                    <td>
                                        <ul id="photos" class="pic-list list-unstyled form-inline"></ul>
                                        <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');" class="btn btn-default btn-sm">选择图片</a>
                                    </td>
                                </tr>
                                <tr>
                                    <th>附件</th>
                                    <td>
                                        <ul id="files" class="pic-list list-unstyled form-inline">
                                        </ul>
                                        <a href="javascript:uploadMultiFile('附件上传','#files','files-item-tpl');" class="btn btn-sm btn-default">选择文件</a>
                                    </td>
                                </tr>
                                <tr>
                                    <th></th>
                                    <td>
                                        <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                            <a class="btn btn-default" href="{:url('businesscard/index/index')}">{:lang('BACK')}</a>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <!-- <div class="form-group">
                        <div class="col-sm-offset-1 col-sm-10">
                            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                            <a class="btn btn-default" href="{:url('businesscard/index/index')}">{:lang('BACK')}</a>
                        </div>
                    </div> -->
                </form>
            </div>
        </div>
        
    </div>
    <include file="public@footer" />
    <script type="text/javascript" src="__STATIC__/js/frontend.js"></script>
    <script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
    </script>
    <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" src="__STATIC__/js/distpicker/distpicker.js"></script>
    <script type="text/javascript">
    $(function() {

        editorcontent = new baidu.editor.ui.Editor({
            toolbars: [
                ['bold', 'link', 'insertimage', 'insertvideo', 'indent', 'justifyleft', 'justifycenter', 'fontsize', 'fullscreen']
            ],
            initialFrameHeight: 200,
            retainOnlyLabelPasted: true,
        });
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {}

        $('.btn-cancel-thumbnail').click(function() {
            $('#thumbnail-preview').attr('src', '/assets/dist/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });

    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('businesscard/Card/select')}?ids=" + selectedCategoriesId, '请选择分类', {
            area: ['300px', '400px'],
            btn: ['确定', '取消'],
            yes: function(index, layero) {
                //do something

                var iframeWin = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
    $(function() {
        var $selector = $('#address-selector');
        var oldAddr = $('#address').val();
        var oldAddrArray = oldAddr.split('|');

        //初始化时获取已有的地址
        $('#address-selector').distpicker({
            province: oldAddrArray[0],
            city: oldAddrArray[1],
            district: oldAddrArray[2],
        });   

        //select onchange时的地址更新
        $selector.children('select').change(function(event) {
            var newaddr = '';
            $.each($selector.children(), function(index, e) {
                newaddr += $(e).val() + '|';
            });
            $('#address').val(newaddr);
        });

    });
    </script>
</body>

</html>